package com.tju.t5.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tju.t5.dao.IUserDAO;
import com.tju.t5.entity.User;
import com.tju.t5.service.IUserService;

public class UserServiceImpl implements IUserService {

	private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
	
	private IUserDAO userDao;
	
	public IUserDAO getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDAO userDao) {
		this.userDao = userDao;
	}

	@Override
	public void createUser(User user) {
		
	}

	@Override
	public void updateUser(User user) {
		
	}

	@Override
	public void deleteUser(User user) {
		
	}

	@Override
	public User getUserByUsername(String username) {
		try
		{
			return userDao.findUserByUsername(username);
		}
		catch(RuntimeException ex)
		{
			throw ex;
		}
	}

	@Override
	public boolean duplicateName(String username) {
		try
		{
			if(userDao.findUserByUsername(username)!= null)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(RuntimeException ex)
		{
			log.error("find duplicate name failed", ex);
			throw ex;
		}
	}

}
